package cn.tedu.restaurant.controller;


import cn.tedu.restaurant.common.JsonResult;
import cn.tedu.restaurant.entity.User;
import cn.tedu.restaurant.service.TopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author JachinLin
 * @since 2020-10-06
 */
@RestController
@RequestMapping("/top")
public class TopController {

    @Autowired
    @Resource
    private TopService topService;
    public static final Integer SUCCESS = 200;

    @RequestMapping("/count")
    public JsonResult<Integer> countTop() {
        JsonResult<Integer> result = new JsonResult<Integer>(SUCCESS);
        result.setData(topService.getCount());
        return result;
    }

    @RequestMapping("/update")
    public JsonResult<Void> updateCount(HttpSession session,@RequestParam("flag") Integer flag) {
        JsonResult<Void> result = new JsonResult<Void>(SUCCESS);

        Integer uid = Integer.valueOf(session.getAttribute("uid").toString());
        String username = session.getAttribute("username").toString();
        topService.updateCount(uid,flag,username);
        return result;
    }


}
